package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.RefundorderService;
import com.youi.service.UserorderService;
import com.youi.entity.Refundorder;
import com.youi.entity.RefundorderVo;
import com.youi.entity.Userorder;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 退款订单控制层
* @author Administrator
*/
@Controller
public class RefundorderController  extends HttpRequestManage{

		@Autowired
		private RefundorderService refundorderService;
		@Autowired
		private UserorderService userorderService;

		/**
		 *查询订单售后详情
		*/
		@ResponseBody
		@RequestMapping("userGetInfo/getRefundorderById")
		public String getRefundorderById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long orderId=getLong("orderId", request);
			Userorder userorder=userorderService.get(orderId);
			if (userorder==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "订单不存在");
			}
			if (userorder.getStatus()!=5) {
				return JsonUtil.toJson(CommonInfoUtil.ISLOCK, "订单非售后状态");
			}
			userorderService.getUserorderMsg(userorder);
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put("orderNo", userorder.getOrderNo());
			Refundorder refundorder=refundorderService.getByParam(params);
			if (refundorder==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLOBJECT, "售后订单不存在");
			}		
			RefundorderVo refundorderVo=new RefundorderVo(userorder, refundorder);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",refundorderVo);//jsonObject	json对象
		}

		
}
